package com.ishansong.ticket.utils;

import com.google.common.base.Preconditions;

/**
 * <p>OrderConst</p>
 * <p>功能描述:  </p>
 *
 * @作者 feng meng
 * @时间 15/9/9 下午4:45
 */
 
public class OrderConst {

    /**
     * 定义订单事件类型
     */
    public static class EventType {
        //下单完成
        public static final int ORDER_SUBMIT = 1;

        //客户自主取件预约
        public static final int ORDER_CUSTOMER_PICKUP_APPOINTMENT = 2;
        //客户自主收件预约
        public static final int ORDER_CUSTOMER_DELIVERY_APPOINTMENT = 3;
        //客户自主流单
        public static final int ORDER_CUSTOMER_CANCELED = 4;
        //闪送员上报取消
        public static final int ORDER_COURIER_CANCELED = 5;

        //系统推单
        public static final int ORDER_PUSH = 10;

        //订单被闪送员抢单
        public static final int ORDER_COURIER_GRABED = 11;
        //闪送员上报取件预约
        public static final int ORDER_COURIER_PICKUP_APPOINTMENT = 12;
        //闪送员上报收件预约
        public static final int ORDER_COURIER_DELIVERY_APPOINTMENT = 13;
        //闪送员上报异常
        public static final int ORDER_COURIER_TASK_EXCEPTION = 14;
        //闪送员取件完成
        public static final int ORDER_COURIER_PICKEDUP = 15;
        //闪送员收件完成
        public static final int ORDER_COURIER_FINISHED = 16;


        //客服指单
        public static final int ORDER_MANUAL_GRABBED = 21;
        //客服并单
        public static final int ORDER_MANUAL_BINDED = 22;
        //客服取件预约
        public static final int ORDER_MANUAL_PICKUP_APPOINTMENT = 23;
        //客服收件预约
        public static final int ORDER_MANUAL_DELIVERY_APPOINTMENT = 24;
        //客服流单
        public static final int ORDER_MANUAL_CANCEL = 25;
        //客服重推
        public static final int ORDER_REPENDING = 26;
        //客服取件完成
        public static final int ORDER_MANUAL_PICKEDUP = 27;
        //客服收件完成
        public static final int ORDER_MANUAL_FINISHED = 28;
        //客服变更寄件人
        public static final int ORDER_MANUAL_CHANGE_FROM = 29;
        //客服变更收件人
        public static final int ORDER_MANUAL_CHANGE_TO = 30;
        //客服处罚闪送员
        public static final int ORDER_MANUAL_PUNISH = 31;

        /**
         * 备注评价(用户对闪送员的评价)
         */
        public static final int ORDER_CARRIER_RANK = 40;

        /**
         * 备注评价（闪送员对用户的评价）
         */
        public static final int ORDER_USER_RANK = 41;

        //积分调整
        public static final int ORDER_SCORE_ADJUST = 50;

        //关闭订单
        public static final int ORDER_CLOSED_BY_CUSTOMER = 60;
        public static final int ORDER_CLOSED_BY_SYSTEM = 61;

        //运营补贴
        public static final int CUSTOMER_SERVICE_SUBSIDY = 62;

        //系统记录
        public static final int ORDER_AUTO_RECORD=9999;


    }

    /** 推送消息类型 */
    public static enum  NotifyCommand{
        GRAB("grab","推送"),
        GRABBED("grabbed","单已经被抢"),
        ABORT("abort", "取消订单"),
        ABORT_TASK("abort_task", "取消订单"),
        UPDATE("update", "更新手机号"),
        ASSIGN("assign", "指单"),
        APPOINTMENT("appointment","预约单"),
        GRABFAIL("grabfail", "抢单失败"),
        GRABSUCC("grabsucc", "抢单成功");

        private String command;
        private String commandDesc;

        NotifyCommand(String command,String commandDesc) {
            this.commandDesc = commandDesc;
            this.command = command;
        }

        public String getCommand() {
            return command;
        }

        public String getCommandDesc() {
            return commandDesc;
        }
        public static NotifyCommand getNotifyCommandByCommand(String command){
            NotifyCommand result=null;
            NotifyCommand[] notifyCommands=NotifyCommand.values();
            for(NotifyCommand notifyCommand:notifyCommands){
                if(notifyCommand.getCommand().equals(command)){
                    result= notifyCommand;
                    break;
                }
            }
            Preconditions.checkArgument(result != null, "不识别的推送命令");
            return result;
        }
    }

    /**
     * 订单角色
     */
    public static enum OrdeRole{
        FROM(0,"寄件人"),
        TO(1,"收件人"),
        DELIVER(2,"闪送员");
        private int type;
        private String typeDesc;

        OrdeRole(int type, String typeDesc) {
            this.type = type;
            this.typeDesc = typeDesc;
        }

        public int getType() {
            return type;
        }

        public String getTypeDesc() {
            return typeDesc;
        }
        public static OrdeRole getOrderType(int type){
            OrdeRole[] ordeRoles =OrdeRole.values();
            for(OrdeRole orderRole:ordeRoles){
                if(orderRole.getType()==type){
                    return orderRole;
                }
            }
            return null;
        }
    }

    /**
     * 订单类型
     */
    public static enum OrderType{
        FromOneToOne(0,"一取一投"),
        FromOneToMany(1,"一取多投"),
        FromManyToOne(2,"多取一投");
        private int type;
        private String typeDesc;

        OrderType(int type, String typeDesc) {
            this.type = type;
            this.typeDesc = typeDesc;
        }

        public int getType() {
            return type;
        }

        public String getTypeDesc() {
            return typeDesc;
        }
        public static OrderType getOrderType(int type){
            OrderType[] orderTypes =OrderType.values();
            for(OrderType orderType:orderTypes){
                if(orderType.getType()==type){
                    return orderType;
                }
            }
            return null;
        }
    }


    /**
     * 交通方式
     */
    public static enum TravelWayEnum{
        //        UNKNOWN(0, "未指定"),
//        ZIXINGCHE(1,"自行车"),
//        DIANDONGCHE(2,"电动车"),
//        QICHE(4,"汽车"),
//        DITIE(8,"地铁"),
//        GONGJIAO(16,"公交车"),
//        MOTUOCHE(32,"摩托车");
        UNKNOWN(0, "未指定"),
        WAY1(1,"电动车/自行车"),
        WAY2(2,"摩托车"),
        WAY3(4,"公共交通"),
        WAY4(8,"汽车");
        private int type;
        private String typeDesc;

        TravelWayEnum(int type, String typeDesc) {
            this.type = type;
            this.typeDesc = typeDesc;
        }

        public int getType() {
            return type;
        }

        public String getTypeDesc() {
            return typeDesc;
        }
        public static TravelWayEnum getTravelWayEnum(int type){
            TravelWayEnum[] travelWays =TravelWayEnum.values();
            for(TravelWayEnum travelWay:travelWays){
                if(travelWay.getType()==type){
                    return travelWay;
                }
            }
            return UNKNOWN;
        }
    }

    /**
     * 预约类型
     */
    public enum AppointType{
        Normal(1,"正常单"),
        PickupAppointType(2,"取件预约"),
        DeliveryAppointType(3,"收件预约");

        private int type;
        private String typeDesc;
        AppointType(int type, String typeDesc) {
            this.type = type;
            this.typeDesc = typeDesc;
        }
        public int getType() {
            return type;
        }

        public String getTypeDesc() {
            return typeDesc;
        }
        public static AppointType getAppointType(int type){
            AppointType[] appointTypes =AppointType.values();
            for(AppointType appointType:appointTypes){
                if(appointType.getType()==type){
                    return appointType;
                }
            }
            return null;
        }
    }

    /**
     * 任务类型
     * type规则，2的1次方起，以此往后排，
     * task表里的type以此加上去，
     * 如果&运算等于本身的值，则表示有该类型
     */
    public static enum TaskType{
        Normal(1,"正常单"),
        Appoint(2,"预约单"),
        Abnormal(4,"异常单"),
        Cancellable(8,"上报取消");

        private int type;
        private String typeDesc;
        TaskType(int type, String typeDesc) {
            this.type = type;
            this.typeDesc = typeDesc;
        }
        public int getType() {
            return type;
        }

        public String getTypeDesc() {
            return typeDesc;
        }
        public static TaskType getTaskType(int type){
            TaskType[] taskTypes =TaskType.values();
            for(TaskType taskType:taskTypes){
                if(taskType.getType()==type){
                    return taskType;
                }
            }
            return null;
        }
    }

    /**
     * 订单来源枚举
     */
    public static enum OrderChannel{
        /**
         * 口袋购物渠道（10以上的渠道为第三方合作的渠道号，注意：partnerNo要与配置文件保持一致）
         */
        KOUDAI(10,"KOUDAI", "口袋购物", "1000"),
        CHULINGMEN(12,"CHULINGMEN", "厨临门", "1002"),
        ZHAOXIANGLAN(13,"ZHAOXIANGLAN", "赵香兰", "1003"),
        JIAKEXIA(14,"JIAKEXIA", "夹克虾", "1004"),

        WEB(1,"WEB", "PC端", ""),
        WEIXIN(2,"WEIXIN", "微信", ""),
        APP(3,"APP", "APP端", ""),
        WAP(4,"WAP", "WAP页", ""),
        BATCH(5, "BATCH", "批量下单", "");
        private int type;
        private String typeDesc;
        private String typeDescCn;
        private String partnerNo;

        OrderChannel(int type,String typeDesc, String typeDescCn, String partnerNo){
            this.type = type;
            this.typeDesc = typeDesc;
            this.typeDescCn = typeDescCn;
            this.partnerNo = partnerNo;
        }

        public int getType(){
            return type;
        }

        public String getTypeDesc(){
            return typeDesc;
        }

        public String getTypeDescCn() {
            return typeDescCn;
        }

        public String getPartnerNo() {
            return partnerNo;
        }

        public static OrderChannel getOrderChannel(int type){
            OrderChannel[] channels = OrderChannel.values();
            for(OrderChannel channel : channels){
                if(channel.getType() == type){
                    return channel;
                }
            }
            return null;
        }

        /**
         * 根据合作伙伴编号获取订单渠道号
         * @param partnerNo
         * @return
         */
        public static OrderChannel getOrderChannel(String partnerNo){
            OrderChannel[] channels = OrderChannel.values();
            for(OrderChannel channel : channels) {
                if (channel.getPartnerNo().equals(partnerNo)) {
                    return channel;
                }
            }
            return null;
        }
    }

    /**
     * 锁状态
     */
    public static enum DispatchStatus{
        CarrierLock(1,"闪送员锁定,不可接单"),
        CarrierUnLock(2,"闪送员非锁定,可接单"),
        CarrierExclude(3,"排除的闪送员,不可接单"),
        CarrierAppVersionExclude(4,"排除特定版本的闪送员,不可接单"),
        CarrierBlackList(5,"闪送员在黑名单中,不可接单");

        private int status;
        private String statusDesc;
        DispatchStatus(int status, String statusDesc) {
            this.status = status;
            statusDesc = statusDesc;
        }

        public int getStatus() {
            return status;
        }

        public String getStatusDesc() {
            return statusDesc;
        }

        public static DispatchStatus getDispatchStatus(int status){
            DispatchStatus[] dispatchStatuses =DispatchStatus.values();
            for(DispatchStatus dispatchStatus:dispatchStatuses) {
                if(dispatchStatus.getStatus()==status){
                    return dispatchStatus;
                }
            }
            return null;
        }
    }
    public static enum PaymentType{
        FROM_PAYMENT(0,"寄方付"),
        TO_PAYMENT(1,"收方付"),
        ONLINE_PAYMENT(2,"在线支付");
        private int type;
        private String typeDesc;

        PaymentType(int type, String typeDesc) {
            this.type = type;
            this.typeDesc = typeDesc;
        }

        public int getType() {
            return type;
        }

        public String getTypeDesc() {
            return typeDesc;
        }
        public static PaymentType getPaymentType(int type){
            PaymentType[] paymentTypes=PaymentType.values();
            for(PaymentType paymentType:paymentTypes){
                if(paymentType.getType()==type){
                    return paymentType;
                }
            }
            return null;
        }
    }

    /**
     * 订单补贴类型
     */
    public static enum SubsidyType{
        COURIER_SUBSIDY(1,"闪送员补贴"),
        CUSTOMER_RENEWAL(2,"客户补款"),
        COURIER_DEBIT(3,"闪送员扣款");

        private int type;
        private String typeDesc;

        SubsidyType(int type, String typeDesc) {
            this.type = type;
            this.typeDesc = typeDesc;
        }

        public int getType() {
            return type;
        }

        public String getTypeDesc() {
            return typeDesc;
        }
        public static SubsidyType getSubsidyTypeDesc(int type){
            SubsidyType[] types = SubsidyType.values();
            for(SubsidyType subsidyType:types){
                if(subsidyType.getType()==type){
                    return subsidyType;
                }
            }
            return null;
        }
    }

    /**
     * 闪送员补贴类型
     * 蛋糕、鲜花、系统原因、人为原因
     */
    public static enum CourierSubsidy{
        CAKE(1,"蛋糕"),
        FLOWER(2,"鲜花"),
        SYSTEM(3,"系统原因"),
        PERSON(4,"人为原因");
        private int type;
        private String typeDesc;

        CourierSubsidy(int type, String typeDesc) {
            this.type = type;
            this.typeDesc = typeDesc;
        }

        public int getType() {
            return type;
        }

        public String getTypeDesc() {
            return typeDesc;
        }
        public static CourierSubsidy getSubsidyTypeDesc(int type){
            CourierSubsidy[] types = CourierSubsidy.values();
            for(CourierSubsidy courierSubsidyType:types){
                if(courierSubsidyType.getType()==type){
                    return courierSubsidyType;
                }
            }
            return null;
        }
    }

    /**
     * 鲜花、蛋糕、海鲜、⾷食品、闪送费
     * 客户补款
     */
    public static enum CustomerRenawal{
        CAKE(1,"蛋糕"),
        FLOWER(2,"鲜花"),
        SEAFOOD(3,"海鲜"),
        FOOD(4,"食品"),
        FEE(5,"闪送费");

        private int type;
        private String typeDesc;

        CustomerRenawal(int type,String typeDesc){
            this.type = type;
            this.typeDesc = typeDesc;
        }

        public int getType() {
            return type;
        }

        public String getTypeDesc() {
            return typeDesc;
        }

        public static CustomerRenawal getCustomerRenawalTye(int type){
            CustomerRenawal[] types = CustomerRenawal.values();
            for(CustomerRenawal renawal : types){
                if(renawal.getType() == type){
                    return renawal;
                }
            }
            return null;
        }
    }

    /**
     * 闪送员扣款类型:
     * 多给钱
     * 物品损坏
     * 物品丢失
     */
    public static enum CourierDebit{
        MORE(1,"多给钱"),
        BROKEN(2,"物品损坏"),
        LOST(3,"物品丢失"),
        NO_MONEY(4,"闪送费"),
        MISTAKE_GOODS(5,"送错物品");

        private int type;
        private String typeDesc;

        CourierDebit(int type,String typeDesc){
            this.type = type;
            this.typeDesc = typeDesc;
        }

        public int getType() {
            return type;
        }

        public String getTypeDesc() {
            return typeDesc;
        }

        public static CourierDebit getCourierDebitType(int type){
            CourierDebit[] types = CourierDebit.values();
            for(CourierDebit debit : types){
                if(debit.getType() == type){
                    return debit;
                }
            }
            return null;
        }

    }

    /**
     * 闪送员扣款类型:
     * 多给钱
     * 物品损坏
     * 物品丢失
     */
    public static enum BackDrawWay{
        ZHIFUBAO(1,"支付宝"),
        BANKCARD(2,"银行卡");

        private int type;
        private String typeDesc;

        BackDrawWay(int type,String typeDesc){
            this.type = type;
            this.typeDesc = typeDesc;
        }

        public int getType() {
            return type;
        }

        public String getTypeDesc() {
            return typeDesc;
        }

        public static BackDrawWay getBackDrawWay(int type){
            BackDrawWay[] types = BackDrawWay.values();
            for(BackDrawWay backDrawWay : types){
                if(backDrawWay.getType() == type){
                    return backDrawWay;
                }
            }
            return null;
        }

    }


    /**
     * 任务类型
     */
    public static enum TaskDtoFlagType{
        Normal(0,"正常单"),
        Appoint(1,"预约单");
        private int type;
        private String typeDesc;
        TaskDtoFlagType(int type, String typeDesc) {
            this.type = type;
            this.typeDesc = typeDesc;
        }
        public int getType() {
            return type;
        }

        public String getTypeDesc() {
            return typeDesc;
        }
        public static TaskDtoFlagType getTaskType(int type){
            TaskDtoFlagType[] taskDtoFlagTypes =TaskDtoFlagType.values();
            for(TaskDtoFlagType taskDtoFlagType:taskDtoFlagTypes){
                if(taskDtoFlagType.getType()==type){
                    return taskDtoFlagType;
                }
            }
            return null;
        }
    }
    /**
     * 城市类型
     */
    public static enum AdjustScoreType{
        CONFIRMED(1,"确认调整"),
        REJECTED(2,"拒绝调整");
        private int type;
        private String typeDesc;
        AdjustScoreType(int type, String typeDesc) {
            this.type = type;
            this.typeDesc = typeDesc;
        }
        public int getType() {
            return type;
        }

        public String getTypeDesc() {
            return typeDesc;
        }
    }

    /**
     * 城市类型
     */
    public static enum CityType{
        One(1,"一线城市"),
        Two(2,"二线城市");
        private int type;
        private String typeDesc;
        CityType(int type, String typeDesc) {
            this.type = type;
            this.typeDesc = typeDesc;
        }
        public int getType() {
            return type;
        }

        public String getTypeDesc() {
            return typeDesc;
        }
        public static CityType getCityType(int type){
            CityType[] cityTypes=CityType.values();
            for(CityType cityType:cityTypes){
                if(cityType.getType()==type){
                    return cityType;
                }
            }
            return null;
        }
    }
    /**
     * 计费策略
     */
    public static enum CityStretegyType{
        Base("0001","5公里内5公斤内19元,每增5公里10元，每增1公斤5元");
        private String id;
        private String desc;
        CityStretegyType(String id, String desc) {
            this.id = id;
            this.desc = desc;
        }

        public String getId() {
            return id;
        }

        public String getDesc() {
            return desc;
        }
        public static CityStretegyType getCityStretegyType(String id){
            CityStretegyType[] cityStretegyTypes=CityStretegyType.values();
            for(CityStretegyType cityStretegyType:cityStretegyTypes){
                if(cityStretegyType.getId().equals(id)){
                    return cityStretegyType;
                }
            }
            return null;
        }
    }
    public static enum CityBillingType{
        LinePath(1,"按直线计费"),
        DrivingPath(2,"按路程计费");
        private int id;
        private String desc;
        CityBillingType(int id, String desc) {
            this.id = id;
            this.desc = desc;
        }

        public int getId() {
            return id;
        }

        public String getDesc() {
            return desc;
        }
        public static CityBillingType getCityBillingType(int id){
            CityBillingType[] cityBillingTypes=CityBillingType.values();
            for(CityBillingType cityBillingType:cityBillingTypes){
                if(cityBillingType.getId()==id){
                    return cityBillingType;
                }
            }
            return null;
        }

    }
    public static enum BannerType{
        WEIXIN(1,"首单9元活动"),
        CHARGE(2,"充值默认活动");
        private int id;
        private String desc;
        BannerType(int id, String desc) {
            this.id = id;
            this.desc = desc;
        }

        public int getId() {
            return id;
        }

        public String getDesc() {
            return desc;
        }
        public static BannerType getBannerType(int id){
            BannerType[] bannerTypes=BannerType.values();
            for(BannerType bannerType:bannerTypes){
                if(bannerType.getId()==id){
                    return bannerType;
                }
            }
            return null;
        }

    }
    //铥铥的手机号
    public static final String SPECIAL_COURIER = "13331021176";

    public static final int TEST_CITY_ID = 10000;

    /** 新手最大的接单数量（接单数大于此数的闪送员定义为老手） */
    public static final int CRITICAL_DELIVER_NUMBER = 3;
    /** 订单重推次数的上限值 */
    public static final int MAX_REPENDING_ORDER_TIMES = 2;

    /** 拉单距离 10公里 **/
    public static final int MAX_POLLING_TASK_DISTANCE = 10000;

    // TODO 需要检查并清理相关联的逻辑
    public static final String PRODUCT_ONE_TO_ONE_NUMBER_PREFIX = "DH0";
    public static final String PRODUCT_ONE_TO_MANY_NUMBER_PREFIX = "DH1";
    public static final String TEST_ONE_TO_ONE_NUMBER_PREFIX = "TDH0";
    public static final String TEST_ONE_TO_MANY_NUMBER_PREFIX = "TDH1";


    /** 客户端同步信息 **/
    public static final String GRABED_REC_APPOINTMENT_TIP_MESSAGE = "您抢的是一单取件预约单，您还可以再继续抢别的正常单！抢单成功后请注意合理安排您的时间，以免耽误预约单的服务时效！";
    public static final String GRABED_TIP_MESSAGE = "如果抢单成功后30分钟内不能到达客户处取件，您的闪送评级将会降低，接单成功概率将会减小。严重者将会被关禁闭，禁闭期间不能接单。";
    public static final String PICKUP_CSF_TIP_MESSAGE = "取件共用时 %s 分钟，你简直就是草上飞啊！送件计时已开始，请即刻启程送件吧，祝你顺利！";
    public static final String PICKUP_GENERAL_TIP_MESSAGE = "取件共用时 %s 分钟，超时%s 分钟,有点慢哟！送件计时已开始，请即刻启程送件吧，祝你顺利！";
    public static final String DELIVERY_FMT_TIP_MESSAGE = "送件用时%s分,时效：%s(分/公里),你是飞毛腿吧";
    public static final String DELIVERY_GENERAL_TIP_MESSAGE = "送件用时%s分,时效：%s(分/公里)";

    /** 这里定义闪送员客户端APP **/
    public static final int NEW_APP_VERSION = 90;


    /**
     * 无优惠费用的优惠类型
     */
    public static final  int NoCouponFeeCouponType=-1;
    /**
     * 一口价优惠劵类型
     */
    public static final  int FixedPriceCouponType=3;

    public static final String TokenKey ="Token_%s";


    /** 优惠券列表key **/
    public static final String USER_COUPON_STATS_LIST_KEY = "userCouponList";

    public static final String USER_DEFAULTED_COUPON_KEY  = "defaultCoupon";

    /** 标准考核时效 **/
    public static final double COURIER_STANDARD_SPEED = 4.0;


    /** 地址类型-发票人地址 */
    public static final String TYPE_INVOICE_ADDRESS = "03";
    /** 地址类型-收件人地址 */
    public static final String TYPE_SHIPPING_ADDRESS = "02";
    /** 地址类型-寄件人地址 */
    public static final String TYPE_BILLING_ADDRESS = "01";

}
